<!--#include file="conn.asp"-->
<!--#include file="chkuser.asp"-->
<%
call adminRight(5)

ID=request("ID")
AllID=request("chk")
curpage=request("curpage")

if request("action")="Del" then
	conn.execute("Delete from Topic where ID="&ID)
	conn.execute("Delete from Topic where ParentID="&ID)
	Go("?showMsgStr=<br><b>主题信息已批量删除成功！</b>|parent|3000|500||")
end if

if request("action")="delall" then
	If AllID="" Then Alert("没有选择数据"):GoBack():response.End()
	conn.execute("delete from Topic where ID in("&AllID&")")
	conn.execute("delete from Topic where ParentID in("&AllID&")")
	Go("?showMsgStr=<br><b>主题信息已批量删除成功！</b>|parent|3000|500||")
end if
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>主题管理</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<script language="javascript" type="text/javascript">
function selcheck(id) {
   var e =document.getElementById(id);
   var objs = e.getElementsByTagName("input");
   if (e.checked){
      e.checked = false;
      for(var i=0; i<objs.length; i++) {
         if(objs[i].type.toLowerCase() == "checkbox" )
         objs[i].checked = false;
      }
   }   else   {
      e.checked = true;
      for(var i=0; i<objs.length; i++) {
         if(objs[i].type.toLowerCase() == "checkbox" )
         objs[i].checked = true;
      }
   }
}
</script>
</head>
<script language="javascript" src="./../kindeditor/kindeditor.js" charset="utf-8"></script>
<body>
    <div id="frame_Toolbar" class="toolbarBg"> 
		<a href="javascript:self.history.back();" class="icoBtn_ct"><span class="btnIco btnBack"></span>返回</a> 
		<a href="javascript:self.location.reload();" class="icoBtn_ct"><span class="btnIco btnReload"></span>刷新</a> 
		<span class="split ftSplit" ></span>
	    <div id="guide">点击<span class="light_orange"> 详细信息 </span>查看详细信息 &nbsp;&nbsp;<a href="?action=addView" style=" font-weight:bold; color:#FF0000">发布新主题</a></div>
		<%
			   Set rs = Server.CreateObject("ADODB.Recordset")
			   sql="select * from Topic where parentid=0 order by id desc"
			   rs.open sql,conn,1,1
	    %>
	    <div class="pageInfo right light_gray">[当前共有<span id="Label_total_top" class="light_bOrange"><%=rs.recordcount%></span>条记录]</div>
    </div>
	<div id="MainContent">
	
<style>
#topic_area{ text-align:center;}
#topic_area .topicTable{border-collapse:collapse; width:90%;}
#topic_area .topicTable td{border:1px solid #CCCCCC; font-size:12px}
#topic_area .title1{ background-color:#dee3e7}
#topic_area .title2{ background-color:#efefef}
#topic_area input.text1{ border:1px solid #cccccc; width:160px}
#topic_area input.text2{ border:1px solid #cccccc; width:250px}
#topic_area input.text3{ border:1px solid #cccccc; width:80px}
#topic_area input.btn{ border:1px solid #999999;}
#editor td{ border:0}
</style>
<div id="topic_area">
<%
const needPass=True
action=request("action")
select case action
case "","viewList":call viewList
case "showView":call showView
case "addView":call addView
case "doAdd":call doAdd
case "replyView":call replyView
case "doReply":call doReply
case "doDel":call doDel
case "doPass":call doPass
case "doCancerPass":call doCancerPass
end select

sub viewList%>
	<form method="POST" id=formdel name="formdel" action="">
     <table class="cTable table tCenter">
	    <tr class="cTitle toolbarBg" id="Title">
		    <td width="7%"><span class="checkbox"><input type="checkbox" name="chkall" onClick="selcheck('MainContent')" /></span></td>
		    <td width="10%"><span class="split ctSplit"></span><div>编号</div></td>
		    <td width="12%"><span class="split ctSplit"></span><div>用户名</div></td>
		    <td width="26%"><span class="split ctSplit"></span>
		    <div>发布主题</div></td>
		    <td width="17%"><span class="split ctSplit"></span>
		    <div>发布日期</div></td>
			<td width="13%"><span class="split ctSplit"></span><div>是否已审核</div></td>
			<td width="15%"><span class="split ctSplit"></span><div>编辑</div></td>
	    </tr>
			<%
			   rs.pagesize=14
			   curpage=clng(Request.QueryString("curpage"))
			   if curpage<=0 then curpage=1
			   if curpage>rs.pagecount then curpage=rs.pagecount
			   if not rs.eof then rs.absolutepage=curpage
			   for i=1 to rs.pagesize
			   if rs.eof then
			   exit for
			   end if
		 %>
		<tr class="trDataList" onMouseOver="this.className='trDataListHover'" onMouseOut="this.className='trDataList'">
			<td><input type="checkbox" name="chk" value="<%=rs("ID")%>" /></td>
			<td><%=rs("ID")%></td>
			<td><%=rs("Name")%></td>
			<td><%=gotTopic(rs("title"),23)%></td>
			<td><%=rs("AddDate")%></td>
		    <td><%
			if needPass=True then
				if rs("Show")=true then
				response.Write("已审核")
				else
				response.Write("<font color=red>未审核</font>")
				end if
			else
				response.Write("已设置无需审核")
			end if
			%></td>
			<td width="15%"><a href="?viewLt=<%=rs("id")%>&action=showView&curpage=<%=curpage%>">详细信息</a>/<a href="?ID=<%=rs("ID")%>&action=Del" onClick="return confirm('确定删除？')">删除</a></td>
		</tr>
		<%
			rs.movenext
			next
        %>	
	</table> 
    <div id="cEndToolbar" class="toolbarBg">
        <div class="pageList">
				<%
				set pageObj=new pager
				response.Write pageObj.link(rs.recordcount,rs.pagesize,curpage,"?curpage=",qryString)
				%>
		<%
			rs.close
			Set rs=nothing
		 %>
	    </div>
	    <div class="pageSelect"><span class="iptSl"><input type="checkbox" name="chkall" onClick="selcheck('MainContent')" /></span><a href="javascript:selcheck('MainContent');"><span class="btnTxt">选择</span></a></div>
	    <span class="split cpSplit" ></span>
	    <div class="pageBtnDo">
	        <div class="icoBtn_do"><input type="image" name="Delete_Button" id="Delete_Button" class="btnIco btnDel" src="images/Empty.gif" onClick="document.formdel.action='?action=delall';return confirm('确定要删除吗?');" style="border-width:0px;" /></div>
	    </div>
	</div>	
	</form>
<%end sub
	
sub showView

	viewLt=request("viewLt")
	set rs=server.CreateObject("adodb.recordset")
	sql="select * from topic where parentid=0 and id="&viewLt
	rs.open sql,conn,1,1
%>
	<div align="right" style="padding:10px">
	<input type="button" value="发表新帖" class="btn" onClick="location='?action=addView'">
	<%if needPass=True then%>
	<input type="button" value="<%if rs("show")=False then response.Write("审核该帖") else response.Write("取消审核") end if%>" class="btn" onClick="location='?action=<%if rs("show")=False then response.Write("doPass") else response.Write("doCancerPass") end if%>&viewLt=<%=viewLt%>&curpage=<%=curpage%>'">
	<%end if%>
	<input type="button" value="发表回复" class="btn" onClick="location='?action=replyView&viewLt=<%=viewLt%>&curpage=<%=curpage%>'">
	<input type="button" value="返回列表" class="btn" onClick="location='?action=viewList&curpage=<%=curpage%>'">
	</div>
	<table width="100%" border="0" cellspacing="0" cellpadding="5" class="topicTable tLeft">
	  <tr class="title1">
		<td style="font-weight:bold">主题：<%=rs("title")%> <%
		if needPass=True then
		if rs("show")=False then response.Write("<strong style='color:#ff0000;padding-left:20px'>该主题还没未审核</strong>")
		end if
		%></td>
	  </tr>
	  <tr class="title2">
		<td>留言者：<%=rs("name")%>, Tel：<%=rs("tel")%>, Email：<%=rs("email")%>, 留言时间：<%=rs("addDate")%>, 浏览：<%=rs("hits")%></td>
	  </tr>
	  <tr>
		<td style="padding:10px">
		<%=replace(rs("content")&"","="&chr(34)&"./","="&chr(34)&"./../")%>
		</td>
	  </tr>
	</table>
	<%
	rs.close
	set rs=nothing
	set rss=server.CreateObject("adodb.recordset")
	sqls="select * from topic where parentid="&viewLt&" order by id asc"
	rss.open sqls,conn,1,1
	do while not rss.eof
	%>
	<div style="padding:15px 0 0 0">
	<a name="replyLt<%=rss("id")%>"></a>
	<table width="100%" border="0" cellspacing="0" cellpadding="5" class="topicTable tLeft">
	  <tr class="title2">
		<td>回复者：<%=rss("name")%>, Tel：<%=rss("tel")%>, Email：<%=rss("email")%>, 留言时间：<%=rss("addDate")%></td>
	  </tr>
	  <tr>
		<td style="padding:10px">
		<%=replace(rss("content")&"","="&chr(34)&"./","="&chr(34)&"./../")%>
		<div align="right"><a href="?action=replyView&replyLt=<%=rss("id")%>&viewLt=<%=viewLt%>&curpage=<%=curpage%>">回复</a> | <a href="?action=doDel&DelLt=<%=rss("id")%>&viewLt=<%=viewLt%>&curpage=<%=curpage%>" onClick="return confirm('确定删除？')">删除</a></div>
		</td>
	  </tr>
	</table>
	</div>
	<%
	rss.movenext
	loop
	rss.close
	set rss=nothing

end sub
sub doDel
	conn.execute("delete from topic where id="&request("DelLt"))
	go("?action=showView&viewLt="&request("viewLt")&"&curpage="&request("curpage"))
end sub
sub doPass
	conn.execute("update topic set show=True where id="&request("viewLt"))
	go("?action=showView&viewLt="&request("viewLt")&"&curpage="&request("curpage"))
end sub
sub doCancerPass
	conn.execute("update topic set show=False where id="&request("viewLt"))
	go("?action=showView&viewLt="&request("viewLt")&"&curpage="&request("curpage"))
end sub

sub addView
%>
	<script language="javascript">
	function checkAdd(f){
		KE.sync('Content');
		if(f.title.value==""){
			alert("请输入留言主题！");
			f.title.focus();
			return false;
		}
		if(f.name.value==""){
			alert("请输入您的姓名！");
			f.name.focus();
			return false;
		}
		if(f.Content.value==""){
			alert("请输入留言内容！");
			KE.focus('Content');
			return false;
		}
	}
	</script>
	<table width="100%" border="0" cellspacing="0" cellpadding="5" style="display:<%=styleDis%>" class="tLeft">
	<form action="?action=doAdd" method="post" onSubmit="return checkAdd(this)">
	  <tr>
		<td width="20%" align="right">留言主题：</td>
		<td><input type="text" name="title" class="text2" /> *</td>
	  </tr>
	  <tr>
		<td align="right">留言者：</td>
		<td><input type="text" name="name" value="网站管理员" class="text2" /> *</td>
	  </tr>
	  <tr>
		<td align="right">留言内容：</td>
		<td>
		<script language="javascript">
		KE.show({
				id : 'Content',
				resizeMode : 1,
				items : [
				'source', 'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
				'removeformat', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', 'link', 'unlink', 'subscript',
			'superscript', 'emoticons'],
				allowFileManager : false,
				allowUpload : false,
				afterCreate : function(id) {
					KE.blur(id);
				}
			});
		</script>
		<div id="editor">
		<textarea name="Content" id="Content" style="width:500px; height:160px;"></textarea>
		</div>
		</td>
	  </tr>
	  <tr>
		<td align="right">&nbsp;</td>
		<td><input type="submit" value=" 确认提交 " class="btn"> <input type="button" value=" 取消返回 " class="btn" onClick="history.back()"></td>
	  </tr>
	</form>
	</table>
<%
end sub

sub doAdd
	set rs=server.CreateObject("adodb.recordset")
	sql="select * from topic"
	rs.open sql,conn,1,3
	rs.addnew()
	rs("title")=trim(request.Form("title"))
	rs("name")=trim(request.Form("name"))
	rs("tel")=trim(request.Form("tel"))
	rs("email")=trim(request.Form("email"))
	rs("content")=trim(request.Form("content"))
	rs("ip")=GetIP()
	rs("show")=True
	rs.update
	alert("发布成功。")
	go("?action=showView&viewLt="&rs("id"))
	rs.close
	set rs=nothing
end sub

sub replyView
	if request("replyLt")<>"" then
	set rs=conn.execute("select * from topic where id="&request("replyLt"))
	tempC="<b>[ 回复: "&rs("name")&"]</b>&nbsp;&nbsp;"
	rs.close
	end if
%>
	<script language="javascript">
	function checkReply(f){
		KE.sync('Content');
		if(f.name.value==""){
			alert("请输入您的姓名！");
			f.name.focus();
			return false;
		}
		if(f.Content.value=="<%=tempC%>"){
			alert("请输入留言内容！");
			KE.focus('Content');
			return false;
		}
	}
	</script>
	<%
	set rs=conn.execute("select * from topic where id="&request("viewLt"))
	replyTitle=rs("title")
	rs.close
	%>
	<table width="100%" border="0" cellspacing="0" cellpadding="5" style="display:<%=styleDis%>" class="tLeft">
	<form action="?action=doReply&curpage=<%=curpage%>" method="post" onSubmit="return checkReply(this)">
	<input type="hidden" name="viewLt" value="<%=request("viewLt")%>">
	<input type="hidden" name="replyLt" value="<%=request("replyLt")%>">
	  <tr>
		<td width="20%" align="right">回复主题：</td>
		<td><%=replyTitle%></td>
	  </tr>
	  <tr style="display:none">
		<td width="20%" align="right">留言主题：</td>
		<td><input type="text" name="title" class="text2" /> *</td>
	  </tr>
	  <tr>
		<td align="right">留言者：</td>
		<td><input type="text" name="name" value="网站管理员" class="text2" /> *</td>
	  </tr>
	  <tr>
		<td align="right">回复内容：</td>
		<td>
		<script language="javascript">
		KE.show({
				id : 'Content',
				resizeMode : 1,
				items : [
				'source', 'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
				'removeformat', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
				'insertunorderedlist', 'link', 'unlink', 'subscript',
			'superscript', 'emoticons'],
				allowFileManager : false,
				allowUpload : false,
				afterCreate : function(id) {
					KE.blur(id);
				}
			});
		</script>
		<div id="editor">
		<textarea name="Content" id="Content" style="width:500px; height:160px;"><%=tempC%></textarea>
		</div>
		</td>
	  </tr>
	  <tr>
		<td align="right">&nbsp;</td>
		<td><input type="submit" value=" 确认提交 " class="btn"> <input type="button" value=" 取消返回 " class="btn" onClick="history.back()"></td>
	  </tr>
	</form>
	</table>
<%
end sub
sub doReply
	set rs=server.CreateObject("adodb.recordset")
	sql="select * from topic"
	rs.open sql,conn,1,3
	rs.addnew()
	rs("parentid")=trim(request.Form("viewLt"))
	rs("title")=trim(request.Form("title"))
	rs("name")=trim(request.Form("name"))
	rs("tel")=trim(request.Form("tel"))
	rs("email")=trim(request.Form("email"))
	rs("content")=trim(request.Form("content"))
	rs("ip")=GetIP()
	rs.update
	alert("回复成功。")
	go("?action=showView&viewLt="&trim(request.Form("viewLt"))&"&curpage="&curpage&"#replyLt"&rs("id")&"")
	rs.close
	set rs=nothing
end sub
%>
</div>

</div>
<script language="javascript">
    function isnum()
    {
        if(event.keyCode<45 || event.keyCode>57)
        {
            event.keyCode=0;
        }
    }                             
</script>
</body>
</html>